class Solution {
   public:
    int firstBadVersion(int n) {
        long long l = 0, r = 0x7fffffff, m;
        while (l < r) {
            m = (r + l) / 2;
            if (isBadVersion(m))
                r = m;
            else
                l = m + 1;
        }
        return l;
    }
};